package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfiguration {
    //创建交换机
    @Bean
    public FanoutExchange fanoutExchange(){
//        两种方法都可以创建
//        return new FanoutExchange("hmall.fanout2");
        return ExchangeBuilder.fanoutExchange("hmall.fanout2").durable(true).build();
    }
//    创建队列
    @Bean
    public Queue fanoutQueue3(){
//        return QueueBuilder.durable("fanout.queue3").build();
        return new Queue("fanout.queue3");
    }
    //    建立交换机与队列的联系
    @Bean
    public Binding fanoutBinding3(Queue fanoutQueue3, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue3).to(fanoutExchange);
    }
    @Bean
    public Queue fanoutQueue4(){
        return QueueBuilder.durable("fanout.queue4").build();
//        return new Queue("fanout.queue4");
    }

    @Bean
    public Binding fanoutBinding4(){
        return BindingBuilder.bind(fanoutQueue4()).to(fanoutExchange());
    }
}
